package com.xoa.controller.hr.staffCare;

import com.xoa.model.hr.staffCare.HrStaffCareWithBLOBs;
import com.xoa.service.hr.staffCare.HrStaffCareService;
import com.xoa.util.CookiesUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import com.xoa.util.dataSource.ContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * @author 左春晖  员工关怀控制层
 * @date 2018/7/20 14:03
 * @desc
 */
@Controller
@RequestMapping("/hr/manage")//     /staff_care
public class HrStaffCareController {

    @Resource
    HrStaffCareService hrStaffCareService;


    //页面映射
    //主页面映射
    @RequestMapping("/staff_care") //  /hr/manage/staff_care
    public String HrStaffCare(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrStaffCare/HrStaffCareManagement";
    }

    //管理頁面
    @RequestMapping("/HrStaffCares") //  /hr/manage/HrStaffCares
    public String HrStaffCares(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrStaffCare/HrStaffCareManage";
    }

    //导入页面
    @RequestMapping("/HrStaffCareimports") //  /hr/manage/HrStaffCareimport
    public String HrStaffCareimports(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrStaffCare/HrStaffCareExport";
    }

    //查询页面
    @RequestMapping("/HrStaffCareselect") //  /hr/manage/HrStaffCareselect
    public String HrStaffCareselect(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrStaffCare/HrStaffCareQuery";
    }
    //新建页面
    @RequestMapping("/HrStaffCareNew") //  /hr/manage/HrStaffCareNew
    public String HrStaffCareNew(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrStaffCare/HrStaffCareNewedit";
    }
    //详情页面
    @RequestMapping("/HrStaffCareDetail") //  /hr/manage/HrStaffCareDetail
    public String HrStaffCareDetail(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrStaffCare/HrStaffCareDetail";

    }

    //下拉框获取
    @RequestMapping("/getHrCodesStaffCare") // /hr/manage/getHrCodesStaffCare
    @ResponseBody
    public BaseWrapper getHrCodesStaffCare(String type) {
        return hrStaffCareService.getHrCodes(type);
    }



    /**
     * 添加
     */
    @ResponseBody
    @RequestMapping("/addHrStaffCares") //  /hr/manage/addHrStaffCares
    public ToJson addHrStaffCares(HttpServletRequest request, HrStaffCareWithBLOBs hrStaffCareWithBLOBs){
        return hrStaffCareService.addHrStaffCare(request,hrStaffCareWithBLOBs);
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/upHrStaffCares")
    public ToJson upHrStaffCares(HttpServletRequest request,HrStaffCareWithBLOBs hrStaffCareWithBLOBs){
        return hrStaffCareService.upHrStaffCare(request,hrStaffCareWithBLOBs);
    }

    /**
     * 删除
     */
    @ResponseBody
    @RequestMapping("/deleteHrStaffCares")
    public ToJson deleteHrStaffCares(String[] careId){
        return hrStaffCareService.deleteHrStaffCare(careId);
    }

    /**
     * 查询  导出
     */
    @ResponseBody
    @RequestMapping("/selectHrStaffCares")
    public ToJson selectHrStaffCares(HttpServletResponse response, HttpServletRequest request, HrStaffCareWithBLOBs hrStaffCareWithBLOBs, Integer page, Integer pageSize, boolean useFlag, String export) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
        return  hrStaffCareService.selectHrStaffCare(response,request,hrStaffCareWithBLOBs,page,pageSize,useFlag,export);
    }


    /**
     * 根据ID查询
     */
    @ResponseBody
    @RequestMapping("/selectHrStaffCareIds")
    public ToJson selectHrStaffCareIds(HttpServletRequest request,Integer careId){
        return hrStaffCareService.selectHrStaffCareId(request,careId);
    }

    /**
     * 导入
     */
    @ResponseBody
    @RequestMapping("/importss")
    public ToJson importss(HttpServletRequest request, HttpServletResponse response, MultipartFile file) {
        return  hrStaffCareService.imports(request,response,file);
    }

}
